package com.ppc.mapper.admin;

import com.github.pagehelper.Page;
import com.ppc.dto.ClaimSolveDTO;
import com.ppc.dto.ComplaintSolveDTO;
import com.ppc.entity.AdminPPC;
import com.ppc.entity.Claim;
import com.ppc.entity.Complaint;
import com.ppc.entity.Employer;
import com.ppc.entity.Recording;
import com.ppc.entity.Requirement;
import com.ppc.entity.Task;
import com.ppc.entity.TempTask;
import com.ppc.entity.Worker;
import com.ppc.vo.AdminClaimDetailVO;
import com.ppc.vo.AdminClaimPageVO;
import com.ppc.vo.AdminComplaintDetailVO;
import com.ppc.vo.AdminComplaintPageVO;
import com.ppc.vo.AdminLoginVO;
import com.ppc.vo.ClaimDetailVO;
import com.ppc.vo.ClaimPageVO;
import com.ppc.vo.ComplaintDetailVO;
import com.ppc.vo.ComplaintPageVO;
import com.ppc.vo.EmployerPageVO;
import com.ppc.vo.WorkerPageVO;
import java.time.LocalDateTime;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * @author dy
 * @date 2023/12/20
 * @description mapper
 */
@Mapper
public interface AdminMapper {


  AdminLoginVO getAdminById(AdminPPC admin);

  String getPasswordById(AdminPPC admin);

  void addAdmin(AdminPPC adminPPC);

  long getEmployerByClaimId(ClaimSolveDTO claimSolveDTO);

  long getWorkerByClaimId(ClaimSolveDTO claimSolveDTO);

  void updateClaimStatus(Claim claim);

  void setEmployerStatus(long employerId, int status);

  Page<AdminClaimPageVO> pageClaimQuery(Integer claimStatus, Integer claimerType);

  void setWorkerStatus(long workerId, int status);

  Page<EmployerPageVO> pageEmployerQuery(Integer UserType, String userName);

  Page<WorkerPageVO> pageWorkerQuery(Integer UserType, String userName);

  void updateComplaintStatus(Complaint complaint);

  long getEmployerByComplaintId(ComplaintSolveDTO complaintSolveDTO);

  Page<AdminComplaintPageVO> pageComplaintQuery(Integer complaintStatus);

  AdminComplaintDetailVO getComplaintDetail(String complaintId);

  AdminClaimDetailVO getClaimDetail(String claimId);

  int getWorkerCreditById(long workerId);

  void setWorkerCredit(int credit, long workerId);

  long getUserIdByWorkId(long workerId);

  void insertRecording(Recording recording);

  int getEmployerCreditById(long employerId);

  void setEmployerCredit(int credit, long employerId);

  long getUserIdByEmployerId(long employerId);

  int getClaimTypeById(Long claimId);

  int getTaskStatusByClaimId(Long claimId);

  void updateTaskStatus(Long claimId, int newStatus);

  Long getTaskIdByClaimId(Long claimId);

  LocalDateTime getExpectedEndTimeByClaimId(Long claimId);

  void updateExpectedEndTimeByClaimId(Long claimId, LocalDateTime newTime);

  @Select("select re.* from task ts LEFT JOIN requirement re on ts.require_id = re.require_id where task_id = #{taskId}")
  Requirement getRequirementById(Long taskId);

  @Select("select wo.* from task ts LEFT JOIN requirement re on ts.require_id = re.require_id " +
      "LEFT JOIN worker wo on wo.worker_id=ts.worker_id where task_id = #{taskId}")
  Worker getWorkerById(Long taskId);

  void updateWorkerWallet(Long workerId, Float workerCount);

  @Select("select em.* from task ts LEFT JOIN requirement re on ts.require_id = re.require_id " +
      "LEFT JOIN employer em on em.employer_id = re.employer_id where task_id = #{taskId}")
  Employer getEmployerById(Long taskId);

  void createMoneyRecording(Recording recording);

  void updateEmployerWallet(Long employerId, Float employerCount);

  @Select("select task.* from claim LEFT JOIN task on claim.task_id=task.task_id where claim_id=#{claimId}")
  Task selectTaskByClaimId(Long claimId);

  @Select("select * from temptask where task_id=#{taskId} and temp_task_status=0 order by temp_task_id desc limit 1")
  TempTask selectTempTaskByTaskId(Long taskId);

  @Select("select temptask.* from claim LEFT JOIN temptask on claim.task_id=temptask.task_id WHERE claim_id=#{claim_id}")
  TempTask selectTempTaskByClaimId(Long claimId);


  void updateRequirement(String requireBroadDesc, String requireTitle, String requireDetailDesc,
      Long requireId);


  void updateTempTask(TempTask tempTask);
}
